/*
2021-7-26
https://leetcode-cn.com/problems/sum-of-digits-of-string-after-convert/
*/

class Solution {
public:
    int getLucky(string s, int k) {
        int ans=0;
        for(auto t:s)
        {
            int num=t-'a'+1;
            while(num)
            {
                ans+=num%10;
                num/=10;
            }
        }

        for(int i=1;i<k;i++)
        {
            int num=0;
            while(ans)
            {
                num+=ans%10;
                ans/=10;
            }
            ans=num;
        }

        return ans;
    }
};

